import { defineStore } from "pinia";
import { useI18n } from "vue-i18n";

export const useI18nStore = defineStore("I18", () => {
  var userLocale = ref<string>(localStorage.getItem("user-locale") || "zh");
  const { t, locale } = useI18n();
  function SetLocale(lang: string) {
    if (locale.value != lang) {
      locale.value = lang;
      localStorage.setItem("user-locale", lang);
      userLocale.value = lang;
    }
  }
  return { userLocale, SetLocale, t };
});
